package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.dto.CommunityReportDTO;
import com.ruoyi.system.domain.vo.CommunityReportVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CommunityReport;
import com.ruoyi.system.service.ICommunityReportService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * reportController
 *
 * @author ruoyi
 * @date 2024-03-26
 */
@RestController
@RequestMapping("/system/report")
public class CommunityReportController extends BaseController {
    @Autowired
    private ICommunityReportService communityReportService;

    /**
     * 查询report列表
     */
    @PreAuthorize("@ss.hasPermi('system:report:list')")
    @GetMapping("/list")
    public TableDataInfo list(CommunityReport communityReport) {
        startPage();
        List<CommunityReport> list = communityReportService.selectCommunityReportList(communityReport);
        return getDataTable(list);
    }

    /**
     * 导出report列表
     */
    @PreAuthorize("@ss.hasPermi('system:report:export')")
    @Log(title = "report", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CommunityReport communityReport) {
        List<CommunityReport> list = communityReportService.selectCommunityReportList(communityReport);
        ExcelUtil<CommunityReport> util = new ExcelUtil<CommunityReport>(CommunityReport.class);
        util.exportExcel(response, list, "report数据");
    }

    /**
     * 获取report详细信息
     */
    @ApiOperation("查询报修表和报修详情表")
    @PreAuthorize("@ss.hasPermi('system:report:query')")
    @GetMapping(value = "/{reportId}")
    public AjaxResult getInfo(@PathVariable("reportId") Long reportId) {
        return success(communityReportService.selectCommunityReportByReportId(reportId));
    }

    /**
     * 新增report
     */
    @PreAuthorize("@ss.hasPermi('system:report:add')")
    @Log(title = "report", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommunityReport communityReport) {
        return toAjax(communityReportService.insertCommunityReport(communityReport));
    }


    /**
     * 修改report
     */

    @PreAuthorize("@ss.hasPermi('system:report:edit')")
    @Log(title = "report", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CommunityReport communityReport) {
        return toAjax(communityReportService.updateCommunityReport(communityReport));
    }

    /**
     * 修改维修工
     */
    @ApiOperation("修改维修工")
    @PreAuthorize("@ss.hasPermi('system:report:assgin')")
    @Log(title = "", businessType = BusinessType.UPDATE)
    @PutMapping("/reportId")
    public AjaxResult edit(@RequestBody CommunityReportDTO communityReportDto) {

        return toAjax(communityReportService.updateCommunityReportUserId(communityReportDto));
    }

    /**
     * 修改状态
     */
    @ApiOperation("修改状态")
    @PreAuthorize("@ss.hasPermi('system:report:finish')")
    @Log(title = "", businessType = BusinessType.UPDATE)
    @PostMapping("/reportId")
    public AjaxResult editStatus(@RequestBody CommunityReportDTO communityReportDto) {

        return toAjax(communityReportService.updateCommunityReportFinish(communityReportDto));
    }


    /**
     * 删除report
     */
    @PreAuthorize("@ss.hasPermi('system:report:remove')")
    @Log(title = "report", businessType = BusinessType.DELETE)
    @DeleteMapping("/{reportIds}")
    public AjaxResult remove(@PathVariable Long[] reportIds) {
        return toAjax(communityReportService.deleteCommunityReportByReportIds(reportIds));
    }
}
